package com.xy.farm.activity.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xy.farm.R;
import com.xy.farm.activity.base.BaseFragment;
import com.xy.farm.activity.farm.AqiIndexActivity;
import com.xy.farm.activity.farm.PlantActivity;
import com.xy.farm.activity.farm.SelectFarmActivity;
import com.xy.farm.activity.fragment.adapter.FarmAdapter;

/**
 * Created by 1174607250 on 2018/8/5.
 */

public class FarmFragment extends BaseFragment
{
    private RecyclerView recyclerView;
    private FarmAdapter adapter;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.fragment_farm, container, false);
        view.findViewById(R.id.btn_more_farm).setOnClickListener(this);
        view.findViewById(R.id.btn_group).setOnClickListener(this);
        view.findViewById(R.id.btn_aqi).setOnClickListener(this);
        view.findViewById(R.id.btn_plant).setOnClickListener(this);
        recyclerView = view.findViewById(R.id.recyclerView);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);
        recyclerView.setHasFixedSize(true);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter((adapter = new FarmAdapter()));
    }
    @Override
    public void onClick(View v)
    {
        super.onClick(v);
        Intent intent;
        switch (v.getId())
        {
            case R.id.btn_more_farm:
                intent = new Intent(getActivity(), SelectFarmActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_group:
                showShortToast("该功能暂未开放");
                break;
            case R.id.btn_aqi:
                intent = new Intent(getActivity(), AqiIndexActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_plant:
                intent = new Intent(getActivity(), PlantActivity.class);
                startActivity(intent);
                break;
        }
    }
}
